home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / TextureDemo.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  3.4 KB  |  75 lines

  1. ' TextureDemo
  2. '
  3. ' Demonstrates basic OpenGL texture loading and rendering.
  4.  
  5.     dim texture (4), handles (1)    ' Textures
  6.     dim index, x, y, image          ' Working variables
  7.  
  8.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  9.     ' Load texture 1
  10.     ' Simple non-mipmapped method
  11.     texture(1) = LoadTexture ("Textures\00001.jpg")
  12.  
  13.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  14.     ' Load texture 2
  15.     ' Simple mipmapped method
  16.     texture(2) = LoadMipmapTexture ("Textures\00002.jpg")
  17.  
  18.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  19.     ' Load texture 3
  20.     ' glTexImage2D method
  21.     
  22.     ' Generate 2 texture handles
  23.     glGenTextures (2, handles)
  24.     image = LoadImage ("Textures\00003.jpg")                        ' Load image
  25.     texture(3) = handles (0)                                        
  26.     glBindTexture (GL_TEXTURE_2D, texture (3))                      ' Bind texture
  27.  
  28.     ' Upload the texture into OpenGL
  29.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  30.  
  31.     ' Because we haven't built any mipmap levels, it is necessary to turn 
  32.     ' off mipmapping for this texture
  33.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  34.  
  35.     DeleteImage (image)                                             ' Done with image. Free up resources
  36.     
  37.     '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  38.     ' Load texture 4
  39.     ' gluBuild2DMipmaps method
  40.     image = LoadImage ("Textures\00004.jpg")                        ' Load image
  41.     texture(4) = handles (1)                                       
  42.     glBindTexture (GL_TEXTURE_2D, texture (4))                      ' Bind texture
  43.  
  44.     ' Upload the texture into OpenGL
  45.     gluBuild2DMipmaps (GL_TEXTURE_2D, 3, ImageWidth(image), ImageHeight(image), ImageFormat(image), ImageDataType(image), image)
  46.     DeleteImage (image)                                             ' Done with image. Free up resources
  47.  
  48.     ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  49.     ' Render textures to quads
  50.     glEnable (GL_TEXTURE_2D)                                        ' Enable texturing
  51.     glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)            ' Clear screen
  52.     glMatrixMode (GL_MODELVIEW)                                     ' Position quads
  53.     glLoadIdentity ()                                        
  54.     glTranslatef (-1.05, 1.05, -2)
  55.  
  56.     index = 1
  57.     for y = 0 to 1
  58.         for x = 0 to 1
  59.             glPushMatrix ()                                         ' Position quad
  60.             glTranslatef (x * 1.1, -y * 1.1, 0)
  61.             glBindTexture (GL_TEXTURE_2D, texture (index))          ' Bind to texture
  62.  
  63.             glBegin (GL_QUADS)                                      ' Draw quad
  64.                 glTexCoord2f (0, 0):    glVertex2f (0,-1)
  65.                 glTexCoord2f (1, 0):    glVertex2f (1,-1)
  66.                 glTexCoord2f (1, 1):    glVertex2f (1, 0)
  67.                 glTexCoord2f (0, 1):    glVertex2f (0, 0)
  68.             glEnd ()
  69.  
  70.             glPopMatrix ()                                          ' Move on to next
  71.             index = index + 1
  72.         next
  73.     next
  74.  
  75.     SwapBuffers ()                                                  ' Swap image to front buffer